<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="/jsp/inc/header.jsp" %>
<c:set var="title" value="模板"/>
<c:set var="rootpath" value="${CONTEXT_PATH}/admin/template/template/"/>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link href="${STATIC_HOST}/css/ligerui.css" rel="stylesheet" type="text/css"/>
    <link href="${STATIC_HOST}/css/common.css" rel="stylesheet" type="text/css" />
    <script src="${STATIC_HOST}/js/common.js" type="text/javascript"></script>
    <script src="${STATIC_HOST}/js/LG.js" type="text/javascript"></script>
    <title>${title}管理</title>
</head>
<body>
<form:form commandName="template" class="l-form" id="mainform" name="mainform" method="post" action="${rootpath}/save.do">
  <div class="l-group l-group-hasicon"><img src="${STATIC_HOST}/images/common/communication.gif"><span>当前位置: 宇宙CMS &gt; <a href="${rootpath}/list.do">${title}管理</a> &gt; ${template.id==0 ? '新增' : '修改'}${title}</span></div>
    <div id="errorLabelContainer">${error.param.wrong}</div>
        <input type="hidden" name="queryParam" value="${queryParam}"/>
		<input type="hidden" name="id" id="id" value="${template.id}"/>
		
      <ul>
      <li class="li_show_left" style="padding-left:30px;"><label for="siteId">站点ID</label> <span style="color:red">*</span>:</li>
       <li class="li_show_right">
           <input type="text" name="siteId" id="siteId" size="10" ltype='text' ligerui='{"width":120}'  value="${template.siteId}"/>
           <input value="..." type="button" class="l-button ellipsis"  onclick="f_select({'targetId':'siteId','selectType':'/admin/site/site'})">
           <span class='formValidatorError'><form:errors path="siteId" /></span>
      </li>
      </ul><!--换行-->
      <ul>
      <li class="li_show_left" style="padding-left:30px;"><label for="name">模板名称</label> <span style="color:red">*</span>:</li>
           <li class="li_show_right">
        <input type="text" name="name" id="name" size="60" maxlength="100" ltype='text'  validate="{required:true,minlength:0,maxlength:100}" value="${template.name}"/>
       <span class='formValidatorError'><form:errors path="name" /></span>
      </li>
      </ul><!--换行-->

      <ul>
      <li class="li_show_left" style="padding-left:30px;"><label for="templateType">模板类型</label> <span style="color:red">*</span>:</li>
       <li class="li_show_right">
          <select name="templateType" id="templateType" ltype="select" size="1" ligerui='{"width":150}' onchange="return checkType();">
              <option value=""  <c:if test="${template.templateType==''}">selected</c:if> >——请选择——</option>
              <option value="1"  <c:if test="${template.templateType==1}">selected</c:if> >频道首页</option>
              <option value="2"  <c:if test="${template.templateType==2}">selected</c:if> >栏目列表页</option>
              <option value="3"  <c:if test="${template.templateType==3}">selected</c:if> >文章最终页</option>
              <option value="4"  <c:if test="${template.templateType==4}">selected</c:if> >区块嵌套页</option>
          </select>
      </li>
      </ul><!--换行-->
      <ul>
      <li class="li_show_left" style="padding-left:30px;"><label for="status">状态</label> <span style="color:red">*</span>:</li>
      <li class="li_show_right">
          <select name="status" id="status" ltype="select" size="1" ligerui='{"width":150}'>
              <option value=""  <c:if test="${template.status==''}">selected</c:if> >——请选择——</option>
              <option value="0"  <c:if test="${template.status==0}">selected</c:if> >关闭</option>
              <option value="1"  <c:if test="${template.status==1}">selected</c:if> >有效</option>
              <option value="2"  <c:if test="${template.status==2}">selected</c:if> >测试</option>
          </select>
      </li>
      </ul><!--换行-->
    <ul>
        <li class="li_show_left" style="padding-left:30px;"><label for="demoId">样例ID</label>(非必选)：</li>
        <li class="li_show_right">
            <input type="text" name="demoId" id="demoId" size="60" maxlength="100" ltype='text'  validate="{required:true,minlength:0,maxlength:100}" value=""/>
            <input type="button" value="预览" id="preview" class="l-button l-button-submit form_submit_button" onclick="return previewTemplate(this.form);"/>
        </li>
    </ul><!--换行-->
      <ul>
      <li class="li_show_left" style="padding-left:30px;"><label for="content">模板内容</label> <span style="color:red">*</span>:</li>
           <li class="li_show_right">
           <textarea cols="100" name="content" id="content" class="l-textarea" style="height: 230px;">${template.content}</textarea>
      </li>
      </ul><!--换行-->
      <ul>
      <li class="li_show_left" style="padding-left:30px;"><label for="memo">备注</label> <span style="color:red">*</span>:</li>
           <li class="li_show_right">
        <input type="text" name="memo" id="memo" size="60" maxlength="100" ltype='text'  validate="{required:true,minlength:0,maxlength:100}" value="${template.memo}"/>
       <span class='formValidatorError'><form:errors path="memo" /></span>
      </li>
      </ul><!--换行-->

  <div class="l-group l-group-hasicon"></div> 
  <input type="submit" value="提交" id="mainformsubmit" class="l-button l-button-submit form_submit_button"/> 
  <c:if test="${fn:contains(header.referer,rootpath)}"><input type="button" value="返回" class="l-button l-button-test" style="float:left;" onClick="location.href='${header.referer}'" /></c:if>
</form:form>
<script type="text/javascript" >
    var mainform = $("#mainform");
    mainform.ligerForm();
    jQuery.metadata.setType("attr", "validate");
    LG.validate(mainform);

    $(function(){
        $("#name").bind('keyup', function (){
            $("#shortName").val($("#name").val());
        });
    });

    function previewTemplate(frm) {
        if(checkForm(frm)){
            frm.target="_blank";
            frm.action="/admin/template/page/preview.do";
            frm.submit();
            frm.target="_self";//还原
            frm.action="${rootpath}/save.do";
        }
    }

    function checkForm(frm){
        var templetName = jQuery("#name").val();
        if(templetName==""){
            LG.tip('模版名称不能为空');
            return false;
        }
        var templetContent = jQuery("#content").val();
        if(templetContent==""){
            LG.tip('模版内容不能为空');
            return false;
        }
        var demoId = jQuery("#demoId").val();
        if(demoId==0){
            LG.tip("请输入样例Id");
            return false;
        }
        return true;
    }
    
    function checkType() {
        var templateType = $("#templateType").val();
        if(templateType==3){
            var text = '<li><input type="text" name="clientType" size="30" maxlength="100" class="l-text" ltype="text" validate="{required:true,minlength:0,maxlength:100}" value=""/>标识（a/m）</li>';
            $("#preview").after(text);
        }else{
            $("#preview + li").empty("");
        }
    }
    
</script>
<div id="scrolltop">返回顶部</div>
<%@ include file="/jsp/inc/footer.jsp"%>
</body>
</html>